//
//  SYMedicineIntroductionCell.m
//  songyao
//
//  Created by work on 16/10/20.
//  Copyright © 2016年 saikuo. All rights reserved.
//

#import "SYMedicineIntroductionCell.h"
#import "SYMedicineModel.h"

@implementation SYMedicineIntroductionCell {
    UILabel *_specificationLabel;
    UILabel *_priceLabel;
    UILabel *_introductionLabel;
    UIButton *_addShoppingCarButton;
    UIButton *_payButton;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _specificationLabel = [[UILabel alloc] init];
        _specificationLabel.textColor = [UIColor contentColor];
        _specificationLabel.font = [UIFont textFieldInputFont];
        [self.contentView addSubview:_specificationLabel];
        [_specificationLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(10);
            make.top.equalTo(self.mas_top).offset(5);
        }];
        
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textColor = [UIColor redColor];
        _priceLabel.font = [UIFont contentFont];
        [self.contentView addSubview:_priceLabel];
        [_priceLabel makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-10);
            make.centerY.equalTo(_specificationLabel.mas_centerY);
        }];
        
        _introductionLabel = [[UILabel alloc] init];
        _introductionLabel.numberOfLines = 0;
        _introductionLabel.textColor = [UIColor contentColor];
        _introductionLabel.font = [UIFont textFieldInputFont];
        [self.contentView addSubview:_introductionLabel];
        [_introductionLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_specificationLabel.mas_left);
            make.right.equalTo(_priceLabel.mas_right);
            make.top.equalTo(_specificationLabel.mas_bottom).offset(10);
        }];
        
        _addShoppingCarButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addShoppingCarButton setTitle:@"加入购物车" forState:UIControlStateNormal];
        [_addShoppingCarButton setBackgroundColor:[UIColor orangeNavControllerTintColor]];
        [self.contentView addSubview:_addShoppingCarButton];
        [_addShoppingCarButton makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(25);
            make.bottom.equalTo(self.mas_bottom);
            make.height.equalTo(@(30));
            make.width.equalTo(@((SCREEN_WIDTH - 75) / 2.0f));
        }];
        
        _payButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_payButton setTitle:@"立即购买" forState:UIControlStateNormal];
        [_payButton setBackgroundColor:[UIColor redColor]];
        [self.contentView addSubview:_payButton];
        [_payButton makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).offset(-25);
            make.bottom.equalTo(self.mas_bottom);
            make.height.equalTo(@(30));
            make.width.equalTo(@((SCREEN_WIDTH - 75) / 2.0f));
        }];
    }
    return self;
}

- (void)setData:(SYMedicineModel *)data {
    _specificationLabel.text = data.specification;
    _priceLabel.text = [NSString stringWithFormat:@"¥%@",data.price];
    _introductionLabel.text = data.introduction;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

+ (CGSize)textSizeWithText:(NSString *)text {
    return [text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 20, MAXFLOAT)
                              options:NSStringDrawingUsesLineFragmentOrigin
                           attributes:@{NSFontAttributeName:[UIFont textFieldInputFont]}
                              context:nil].size;
}

@end
